package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.Drug;
import me.xue.communityhealth.model.DrugUnit;
import me.xue.communityhealth.repo.DrugUnitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugUnitService implements BaseService<DrugUnit, Integer> {

    private final DrugUnitRepository drugUnitRepository;

    @Autowired
    public DrugUnitService(DrugUnitRepository drugUnitRepository) {
        this.drugUnitRepository = drugUnitRepository;
    }

    @Override
    public int save(DrugUnit produceUnit) {
        return drugUnitRepository.save(produceUnit);
    }

    @Override
    public int update(DrugUnit produceUnit) {
        return drugUnitRepository.update(produceUnit);
    }

    @Override
    public int delete(Integer which) {
        return drugUnitRepository.delete(which);
    }

    public DrugUnit findOne(Integer which) {
        DrugUnit drugUnit = drugUnitRepository.findOne(which);
        if (drugUnit == null) {
            throw new ObjectNotFoundException();
        }
        return drugUnit;
    }

    @Override
    public List<DrugUnit> findAll() {
        return drugUnitRepository.findAll();
    }
}
